// 红外仪器配置文件
import { unitMap } from '@/config';
import { formateYYYYMMDDHHMMss, formatUnit, formatVersion } from './format';
import type { ConfigItem } from '@/types/tester';

const requestFlagMap = {
  '0x00': '移动端',
  '0x01': '设备端',
}

const typeCodeMap = {
  '0x00000001': '任务下发',
  '0x80000001': '任务接收确认',
  '0x00000002': '请求连接',
  '0x80000002': '请求连接确认',
  '0x00000003': '请求检测数据',
  '0x80000003': '检测数据文件上传',
}

const zipFlagMap = {
  '0x00': '未压缩',
  '0x01': 'gzip压缩',
}

const encryptFlagMap = {
  '0x00': '未加密',
  '0x01': '加密',
}

const manufacturerMap = {
  '0x00': '其他厂家',
  '0x05': 'FLIR',
}

const dataFormatMap = {
  '0x01': 'XML',
}

const weatherMap = {
  '0x01': '晴',
  '0x02': '阴天',
  '0x03': '雨',
  '0x04': '雪',
  '0x05': '雾',
  '0x06': '雷雨',
  '0x07': '多云',
}

export const infraredConfig: ConfigItem[] = [
  {
    label: '报文头',
    key: 'header',
    start: 0,
    length: 4,
    dataType: 'int32',
    hide: true,
  },
  {
    label: '版本号',
    key: 'version',
    start: 4,
    length: 1,
    dataType: 'unit8',
    hide: true,
  },
  {
    label: '序号',
    key: 'number',
    start: 5,
    length: 2,
    dataType: 'unit16',
    hide: true,
  },
  {
    label: '请求标志',
    key: 'requestFlag',
    start: 7,
    length: 1,
    dataType: 'unit8',
    format: value => formatUnit(value, requestFlagMap),
    hide: true,
  },
  {
    label: '数据总长',
    key: 'dataLength',
    start: 8,
    length: 8,
    dataType: 'int64',
    hide: true,
  },
  {
    label: '报文类型',
    key: 'typeCode',
    start: 16,
    length: 4,
    dataType: 'int32',
    format: value => formatUnit(value, typeCodeMap),
    hide: true,
  },
  {
    label: '压缩标志',
    key: 'compressFlag',
    start: 20,
    length: 1,
    dataType: 'unit8',
    format: value => formatUnit(value, zipFlagMap),
    hide: true,
  },
  {
    label: '加密标志',
    key: 'encryptFlag',
    start: 21,
    length: 1,
    dataType: 'unit8',
    format: value => formatUnit(value, encryptFlagMap),
    hide: true,
  },
  {
    label: '仪器厂商',
    key: 'manufacturer',
    start: 22,
    length: 1,
    dataType: 'unit8',
    format: value => formatUnit(value, manufacturerMap),
    hide: true,
  },
  {
    label: '备用',
    key: 'reserve',
    start: 23,
    length: 15,
    dataType: 'unit8',
    hide: true,
  },
  {
    label: '业务数据格式',
    key: 'dataFormat',
    start: 38,
    length: 1,
    dataType: 'unit8',
    format: value => formatUnit(value, dataFormatMap),
    hide: true,
  },
  {
    label: '业务数据长度',
    key: 'dataLength2',
    start: 39,
    length: 8,
    dataType: 'int32',
    hide: true,
  },
  {
    label: '检测数据文件长度',
    key: 'fileLength',
    start: 47,
    length: 8,
    dataType: 'int64',
    hide: true,
  },
  {
    label: '文件长度',
    key: 'fileLength',
    start: 55,
    length: 4,
    dataType: 'int32',
    serverKey: 'fileLength',
  },
  {
    label: '版本号',
    key: 'version2',
    start: 59,
    length: 4,
    dataType: 'unit8',
    format: value => formatVersion(String(value)),
    serverKey: 'ganonicalVNumber',
    hide: true,
  },
  {
    label: '文件时间',
    key: 'datetime',
    start: 63,
    length: 8,
    dataType: 'int64',
    serverKey: 'fileCreateTime',
    format: value => formateYYYYMMDDHHMMss(String(value)),
  },
  {
    label: '备注',
    key: 'remark',
    start: 0,
    length: 0,
    dataType: 'char',
    serverKey: 'remark',
    editable: true,
    editType: 'input',
  },
  {
    label: '文件路径',
    key: 'filePath',
    start: 363,
    length: 34,
    dataType: 'char',
    serverKey: 'fileFull',
  },
  {
    label: '设备路径',
    key: 'siteName',
    start: 71,
    length: 118,
    dataType: 'char',
    serverKey: 'siteName',
    hide: true,
  },
  {
    label: '站点编码',
    key: 'siteCode',
    start: 189,
    length: 42,
    dataType: 'char',
    serverKey: 'siteCode',
    hide: true,
  },
  {
    label: '天气',
    key: 'weather',
    start: 231,
    length: 1,
    dataType: 'unit8',
    format: value => formatUnit(value, weatherMap),
    serverKey: 'weather',
  },
  {
    label: '温度',
    key: 'temperature',
    start: 232,
    length: 4,
    dataType: 'float',
    precision: 1,
    serverKey: 'temperature',
    unit: unitMap['0x11'],
  },
  {
    label: '湿度',
    key: 'humidity',
    start: 236,
    length: 1,
    dataType: 'int8',
    serverKey: 'humidity',
  },
  {
    label: '仪器厂家',
    key: 'manufacturer',
    start: 237,
    length: 32,
    dataType: 'char',
    serverKey: 'instrumentManufacturers',
    hide: true,
  },
  {
    label: '仪器型号',
    key: 'model',
    start: 269,
    length: 32,
    dataType: 'char',
    serverKey: 'instrumentModel',
    hide: true,
  },
  {
    label: '仪器版本号',
    key: 'version',
    start: 301,
    length: 4,
    dataType: 'unit8',
    format: value => formatVersion(String(value)),
    serverKey: 'instrumentVNumber',
    hide: true,
  },
  {
    label: '仪器序列号',
    key: 'serialNumber',
    start: 305,
    length: 32,
    dataType: 'char',
    serverKey: 'instrumentNumber',
    hide: true,
  },
  {
    label: '系统频率',
    key: 'systemFrequency',
    start: 337,
    length: 4,
    dataType: 'float',
    serverKey: 'sysFrequency',
  },
  {
    label: '图谱数量',
    key: 'graphNumber',
    start: 341,
    length: 2,
    dataType: 'int16',
    serverKey: 'atlasCount',
  },
  {
    label: '经度',
    key: 'longitude',
    start: 343,
    length: 8,
    dataType: 'float',
    serverKey: 'longitude',
    hide: true,
  },
  {
    label: '纬度',
    key: 'latitude',
    start: 351,
    length: 8,
    dataType: 'float',
    serverKey: 'latitude',
    hide: true,
  },
  {
    label: '海拔',
    key: 'elevation',
    start: 359,
    length: 4,
    dataType: 'float',
    serverKey: 'elevation',
    hide: true,
  },
];
